# Copyright 2024 Bytedance Ltd. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from fastapi.testclient import TestClient

from sandbox.datasets.types import EvalResult, Prompt, TestConfig
from sandbox.server.online_judge_api import GetPromptByIdRequest, GetPromptsRequest, SubmitRequest
from sandbox.server.server import app

client = TestClient(app)


async def test_provided_data_get():
    row = {'id': 0, 'labels': '{}', 'content': 'this is a prompt'}
    request = GetPromptsRequest(dataset='this doesn\'t matter',
                                config=TestConfig(dataset_type='AutoEvalDataset', provided_data=[row, row]))
    response = client.post('/get_prompts', json=request.model_dump())
    assert response.status_code == 200
    results = [Prompt(**sample) for sample in response.json()]
    assert len(results) == 2
    assert results[0].prompt == row['content']


async def test_provided_data_get_id():
    row = {'id': 0, 'labels': '{}', 'content': 'this cis a prompt'}
    request = GetPromptByIdRequest(dataset='this doesn\'t matter',
                                   id=0,
                                   config=TestConfig(dataset_type='AutoEvalDataset', provided_data=row))
    response = client.post('/get_prompt_by_id', json=request.model_dump())
    assert response.status_code == 200
    result = Prompt(**response.json())
    assert result.prompt == row['content']


async def test_provided_data_submit_passed():
    row = {
        "content":
            "\n有一个名为'Hitters_X_train.csv'的数据集，数据的前两行如下：\n| Unnamed: 0         |   AtBat |   Hits |   HmRun |   Runs |   RBI |   Walks |   Years |   CAtBat |   CHits |   CHmRun |   CRuns |   CRBI |   CWalks |   LeagueN |   DivisionW |   PutOuts |   Assists |   Errors |   NewLeagueN |\n|:-------------------|--------:|-------:|--------:|-------:|------:|--------:|--------:|---------:|--------:|---------:|--------:|-------:|---------:|----------:|------------:|----------:|----------:|---------:|-------------:|\n| -Darryl Strawberry |     475 |    123 |      27 |     76 |    93 |      72 |       4 |     1810 |     471 |      108 |     292 |    343 |      267 |         1 |           0 |       226 |        10 |        6 |            1 |\n| -Glenn Wilson      |     584 |    158 |      15 |     70 |    84 |      42 |       5 |     2358 |     636 |       58 |     265 |    316 |      134 |         1 |           0 |       331 |        20 |        4 |            1 |\n\n问题：\n对球员的辅助次数（Assists）和失误（Errors）进行关联性分析。\n\n回答需要满足以下要求：\n1. 数据文件为'Hitters_X_train.csv'，请严格参考数据的表头，使用python代码进行回答问题。\n2. 使用'pandas.read_csv'来读取数据，默认数据在代码的同一路径下。\n3. 分析代码写成叫'proc_data()'的函数，且该函数不需要任何输入参数，用问题中的相关性系数作为返回值。\n",
        "id":
            3,
        "labels":
            "{\"execution_language\":\"python\", \"fewshot\":\"问题：有一个名为'person.csv'的数据集，数据 schema 如下：\\n\\n+-------------+---------+\\n| Column Name | Type    |\\n+-------------+---------+\\n| id          | int     |\\n| email       | varchar |\\n+-------------+---------+\\n\\n其中 id 是该表的主键列(具有唯一值的列)。该表的每一行包含一封电子邮件。电子邮件将不包含大写字母。\\n \\n使用 python pandas 库编写解决方案 删除 所有重复的电子邮件，只保留一个具有最小 id 的唯一电子邮件。\\n\\n回答需要满足以下要求：\\n1. 数据文件为'person.csv'，请严格参考数据的表头，使用python代码进行回答问题。\\n2. 使用'pandas.read_csv'来读取数据，默认数据在代码的同一路径下。\\n3. 分析代码写成叫'proc_data()'的函数，且该函数不需要任何输入参数，用处理后的 dataframe 作为返回值。\\n\\n答案：\\n```python\\nimport pandas as pd\\n\\ndef proc_data():\\n    # 读取 CSV 文件并创建 DataFrame\\n    df = pd.read_csv('person.csv')\\n\\n    # 将 email 列转换为小写\\n    df['email'] = df['email'].str.lower()\\n\\n    # 根据 email 列进行排序，再根据 id 列进行排序\\n    df.sort_values(['email', 'id'], inplace=True)\\n\\n    # 删除重复的电子邮件，只保留具有最小 id 的唯一电子邮件\\n    df.drop_duplicates(subset='email', keep='first', inplace=True)\\n\\n    return df\\n```\\n\\n----------------\\n\\n问题：有一个名为'animals.csv'的数据集，数据 schema 如下：\\n\\n+-------------+--------+\\n| Column Name | Type   |\\n+-------------+--------+\\n| name        | object |\\n| species     | object |\\n| age         | int    |\\n| weight      | int    |\\n+-------------+--------+\\n\\n编写一个解决方案来列出体重严格超过 100 千克的动物的名称。按体重降序返回动物名称。\\n\\n回答需要满足以下要求：\\n1. 数据文件为'animals.csv'，请严格参考数据的表头，使用python代码进行回答问题。\\n2. 使用'pandas.read_csv'来读取数据，默认数据在代码的同一路径下。\\n3. 分析代码写成叫'proc_data()'的函数，且该函数不需要任何输入参数，用一个 python list 作为返回值。\\n\\n答案：\\n```python\\nimport pandas as pd\\n\\ndef proc_data():\\n    # 读取 CSV 文件并创建 DataFrame\\n    df = pd.read_csv('animals.csv')\\n\\n    # 筛选体重严格超过 100 千克的动物\\n    filtered_df = df[df['weight'] > 100]\\n\\n    # 按体重降序排序\\n    sorted_df = filtered_df.sort_values('weight', ascending=False)\\n\\n    # 获取动物名称列表\\n    animal_names = sorted_df['name'].tolist()\\n\\n    return animal_names\\n```\\n\\n----------------\", \"programming_language\":\"python\", \"task_id\":\"data_analysis_python/1\"}",
        "test":
            "{\"asset\":\"{\\\"Hitters_X_train.csv\\\": null, \\\"Hitters_X_train.csv\\\": \\\"IiIsIkF0QmF0IiwiSGl0cyIsIkhtUnVuIiwiUnVucyIsIlJCSSIsIldhbGtzIiwiWWVhcnMiLCJDQXRCYXQiLCJDSGl0cyIsIkNIbVJ1biIsIkNSdW5zIiwiQ1JCSSIsIkNXYWxrcyIsIkxlYWd1ZU4iLCJEaXZpc2lvblciLCJQdXRPdXRzIiwiQXNzaXN0cyIsIkVycm9ycyIsIk5ld0xlYWd1ZU4iCiItRGFycnlsIFN0cmF3YmVycnkiLDQ3NSwxMjMsMjcsNzYsOTMsNzIsNCwxODEwLDQ3MSwxMDgsMjkyLDM0MywyNjcsMSwwLDIyNiwxMCw2LDEKIi1HbGVubiBXaWxzb24iLDU4NCwxNTgsMTU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mluIE1jUmV5bm9sZHMiLDU2MCwxNjEsMjYsODksOTYsNjYsNCwxNzg5LDQ3MCw2NSwyMzMsMjYwLDE1NSwxLDEsMzMyLDksOCwxCiItQm9iIEtlYXJuZXkiLDIwNCw0OSw2LDIzLDI1LDEyLDcsMTMwOSwzMDgsMjcsMTI2LDEzMiw2NiwwLDEsNDE5LDQ2LDUsMAoiLVRpbSBIdWxldHQiLDUyMCwxMjAsMTcsNTMsNDQsMjEsNCw5MjcsMjI3LDIyLDEwNiw4MCw1MiwwLDEsNzAsMTQ0LDExLDAKIi1SeW5lIFNhbmRiZXJnIiw2MjcsMTc4LDE0LDY4LDc2LDQ2LDYsMzE0Niw5MDIsNzQsNDk0LDM0NSwyNDIsMSwwLDMwOSw0OTIsNSwxCiItTWlrZSBIZWF0aCIsMjg4LDY1LDgsMzAsMzYsMjcsOSwyODE1LDY5OCw1NSwzMTUsMzI1LDE4OSwxLDAsMjU5LDMwLDEwLDAK\\\"}\", \"code\":\"#<INSERT>\\n\\nanswer = proc_data()\\nassert round(answer, 3) == 0.642\\n    \"}"
    }
    canonical_solution = "\nimport pandas as pd\n\ndef proc_data():\n    # Load the data from the uploaded CSV file\n    hitters_data = pd.read_csv('Hitters_X_train.csv')\n\n    # Calculate the Pearson correlation coefficient between \"Assists\" and \"Errors\"\n    correlation = hitters_data[\"Assists\"].corr(hitters_data[\"Errors\"])\n    \n    return correlation"
    request = SubmitRequest(dataset='this doesn\'t matter',
                            id=0,
                            config=TestConfig(dataset_type='AutoEvalDataset', provided_data=row),
                            completion=f'''
```python
{canonical_solution}
```
''')
    response = client.post('/submit', json=request.model_dump())
    assert response.status_code == 200
    result = EvalResult(**response.json())
    assert result.accepted == True

    request.config.extra['append_flag'] = True
    response = client.post('/submit', json=request.model_dump())
    assert response.status_code == 200
    result = EvalResult(**response.json())
    assert result.accepted == True
    print(result)
